package com.example.fitnessservice.module.dao.placemapper;

import com.example.fitnessservice.module.pojo.CourseDetails;
import com.example.fitnessservice.module.pojo.CourseDetailsCamp;
import com.example.fitnessservice.module.pojo.Place;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

//场地的信息
@Mapper
public interface PlaceMapper {

    /**
     * 修改场馆的开馆和闭馆时间
     *
     * @param placeId
     * @param startTime
     * @param endTime
     * @return
     */
    @Update("update place set start_time = #{startTime}, end_time = #{endTime} where id = #{id}")
    public int updatePlaceTime(@Param("id") Integer placeId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /**
     * 查询场馆中的课程，并且查出课程的教练信息
     * @param placeId
     * @return
     */
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "courseName", column = "course_name"),
            @Result(property = "placeId", column = "place_id"),
            @Result(property = "courseCoachId", column = "course_coach_id"),
            @Result(property = "courseStartTime", column = "course_start_time"),
            @Result(property = "courseEndTime", column = "course_end_time"),
            @Result(property = "courseStatus", column = "course_status"),
            @Result(property = "courseDescription", column = "course_description"),
            @Result(property = "course_money", column = "courseMoney"),
            @Result(property = "courseNum", column = "course_num"),
            @Result(property = "courseCoachId", column = "course_coach_id", one = @One(select = "com.example.fitnessservice.module.dao.coachmapper.CoachMapper.findClassByCid"))
    })
    @Select("select * from course_details where place_id = #{placeId}")
    public List<CourseDetails> findCourseInPlace(Integer placeId);

    /**
     * 查询场馆中的训练营，并且查出训练营的教练信息
     * @param placeId
     * @return
     */
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "courseName", column = "course_name"),
            @Result(property = "placeId", column = "place_id"),
            @Result(property = "courseCoachId", column = "course_coach_id"),
            @Result(property = "courseStartTime", column = "course_start_time"),
            @Result(property = "courseEndTime", column = "course_end_time"),
            @Result(property = "courseStatus", column = "course_status"),
            @Result(property = "courseDescription", column = "course_description"),
            @Result(property = "courseMoney", column = "course_money"),
            @Result(property = "courseNum", column = "course_num"),
            @Result(property = "courseCoach", column = "course_coach_id", many = @Many(select = "com.example.fitnessservice.module.dao.coachmapper.CoachMapper.findClassByCid"))
    })
    @Select("select * from course_details_camp where place_id = #{placeId}")
    public List<CourseDetailsCamp> findCampInPlace(Integer placeId);

    @Select("select * from place where id = #{placeId}")
    public Place findPlaceById(Integer placeId);
}
